<template>
	<div class="app" ref="box">
		<router-view />
	</div>
</template>

<script>
	let token = localStorage.getItem("token");

	if (token == '' || token == null) {
	
		localStorage.setItem("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuaWNrTmFtZSI6IueOi-mjniIsImF2YXRhckxpbmsiOiJodHRwczovL2ltZzEuYmFpZHUuY29tL2l0L3U9ODczMTA2NzY1LDI1ODc0MTAwNDcmZm09MjUzJmFwcD0xMzgmc2l6ZT13OTMxJm49MCZmPUpQRUcmZm10PWF1dG8_c2VjPTE2NjEyNzQwMDAmdD00MTdiODVlOTRlN2QzMGVlMjFhOWJhZTQ0NjFjYmM2YyIsIklEIjoiMTUzNzcyNDQwNzYyMzc5NDY4OCIsImV4cCI6MTY2MTkxMjUxOX0.J__mxVNo9ecbUI-6mvdrRlDcRj3e6ZB0T05MQk1xGOs");
		
	}
	import jwtDecode from 'jwt-decode';
	export default {
		name: 'App',
		created() {
			
			//渲染用户信息
			let token = localStorage.getItem("token");
			if (token !== '' && token !== null) {
				
				//解析用户信息
				const userInfo = jwtDecode(token);
				//判断当前时间是否小于token的有效时间
				if (new Date().getTime() < new Date(userInfo.exp * 1000).getTime()) {
					//建立连接
					this.$websocket.Init(userInfo.ID);
				}
			
			}
			
			
		},
		mounted() {
		      document.addEventListener('visibilitychange', this.checkNameExpired);
		    },
		    beforeDestroy() {
		      document.removeEventListener('visibilitychange', this.checkNameExpired);
		    },
		    methods: {
		      checkNameExpired() {
		        console.log("33333333yoke")
				let token=localStorage.getItem("token");
		        if (document.hidden == false && global.token != token) {
		          global.token= token //当前登录的用户信息与全局存的用户信息不同，覆盖新的用户信息，否则是最初设的值
				  
		          // 这里样式可以根据项目优化，刷新页面
		          window.location.reload();
				  console.log("开始刷新")
		        }
		      }
		    }

	}
</script>

<style>
	body {
		margin: 0;
		width: 100%;
		/* height: 100%; */

	}

	html {
		width: 100%;
		height: 100%;
	}

	.app {
		width: 100%;
		height: 100%;
	}
</style>
